
Ext.define('FrontSuite.view.NavAccordion', {
    id:           'accordion-nav-panel',
    extend:       'Ext.Panel',  // defines the superclass. results in class inheritance.

    defaults : {
        bodyStyle: 'padding:10px'
    },
    layout: {
        type          : 'accordion',
        titleCollapse : false,
        animate       : true,
        activeOnTop   : true
    },

    items               : null,         // don't know the items until construction time
    screenTreePanel     : null,
    tableTreePanel      : null,
    dataImportTreePanel : null,
    reportTreePanel     : null,
    fileTreePanel       : null,
   
    constructor: function (id) {
        if (id) {
            this.id = id;
        }
        var navbar = this;

        this.tableTreePanel      = Ext.create('FrontSuite.view.TableTreePanel');
        this.screenTreePanel     = Ext.create('FrontSuite.view.ScreenTreePanel');
        // this.dataImportTreePanel = Ext.create('FrontSuite.view.DataImportTreePanel');
        // this.reportTreePanel     = Ext.create('FrontSuite.view.ReportTreePanel');
        this.fileTreePanel       = Ext.create('FrontSuite.view.FileTreePanel');

        this.items = [
            {
                title      : 'Database Tables/Views',
                id         : 'tables-panel',
                autoScroll : true,
                items : [
                    this.tableTreePanel
                ],
                tools: [
                    {
                        type:'refresh',
                        tooltip: 'Refresh Table Tree',
                        handler: function(event, toolEl, panel) { navbar.tableTreePanel.refresh(); }
                    }
                ]
            },
            {
                title      : 'View Organizer',
                id         : 'tasks-panel',
                autoScroll : true,
                items : [
                    this.screenTreePanel
                ],
                tools: [
                    {
                        type:'refresh',
                        tooltip: 'Refresh View Tree',
                        handler: function(event, toolEl, panel) { navbar.screenTreePanel.refresh(); }
                    }
                ]
            },
            //{
            //    title      : 'Data Import',
            //    id         : 'dataImport-panel',
            //    autoScroll : true,
            //    items : [
            //        this.dataImportTreePanel
            //    ]
            //},
            //{
            //    title      : 'Reports',
            //    id         : 'report-panel',
            //    autoScroll : true,
            //    items : [
            //        this.reportTreePanel
            //    ]
            //},
            {
                title      : 'Files',
                id         : 'file-panel',
                autoScroll : true,
                items : [
                    this.fileTreePanel
                ],
                tools: [
                    {
                        type:'refresh',
                        tooltip: 'Refresh file tree',
                        handler: function(event, toolEl, panel){
                            storeExpandedDocumentTreeNodes();
                            navbar.fileTreePanel.store.reload();
                       }
                   }
                ]
            }
        ];
        this.superclass.constructor.call(this, id);
        return(this);
    },

    refresh: function () {
        if (this.screenTreePanel     && this.screenTreePanel.refresh)     this.screenTreePanel.refresh();
        if (this.tableTreePanel      && this.tableTreePanel.refresh)      this.tableTreePanel.refresh();
        if (this.dataImportTreePanel && this.dataImportTreePanel.refresh) this.dataImportTreePanel.refresh();
        if (this.reportTreePanel     && this.reportTreePanel.refresh)     this.reportTreePanel.refresh();
        // if (this.fileTreePanel       && this.fileTreePanel.refresh)       this.fileTreePanel.refresh();
    }
});

